package com.pri.chat.activity;

import com.google.gson.Gson;
import com.netease.nim.uikit.net.SharedHelper;
import com.netease.nim.uikit.net.entity.BaseBean;
import com.netease.nim.uikit.net.entity.TiXianNote;
import com.netease.nim.uikit.net.rxjava.HttpMethods;
import com.netease.nim.uikit.net.subscribers.ProgressSubscriber;
import com.netease.nim.uikit.net.subscribers.SubscriberOnNextListener;
import com.pri.chat.R;
import com.pri.chat.adapter.TiXianNoteListAdapter;
import com.pri.chat.base.BaseActivity;
import com.pri.chat.model.UserModel;
import com.pri.chat.utils.Des3Util;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/23
 */
public class TiXianNoteListActivity extends BaseActivity {
    @BindView(R.id.rec_recharge_list)
    RecyclerView recRechargeList;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_tixiannote_layout;
    }

    @Override
    protected void initView() {
        setTitle("提现记录");
        initRv();
    }
    private List<TiXianNote> mlist = new ArrayList<>();
    private TiXianNoteListAdapter mAdapter;
    private void initRv() {
        LinearLayoutManager linearLayoutManager =new LinearLayoutManager(this);
        recRechargeList.setLayoutManager(linearLayoutManager);
        recRechargeList.setNestedScrollingEnabled(false);
        mAdapter=new TiXianNoteListAdapter(R.layout.item_recharge_list,mlist);
        recRechargeList.setAdapter(mAdapter);
    }


    @Override
    protected void initData() {
        SubscriberOnNextListener<BaseBean<List<TiXianNote>>> onNextListener = baseBean -> {
            mlist.addAll(baseBean.getData());
            mAdapter.notifyDataSetChanged();
            System.out.println("----"+new Gson().toJson(baseBean));
        };
        UserModel regModel = new UserModel();//登录上传参数
        regModel.setMemberId(SharedHelper.readId(this));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(regModel));
        HttpMethods.getInstance().listTiXian(new ProgressSubscriber<>(onNextListener, this, true), requestBody);
    }
}
